package com.hw.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "CoServlet",urlPatterns = "/cookie")
public class CoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String key = request.getParameter("key");
        String value = request.getParameter("value");
        Cookie name = new Cookie("key",key); // 中文转码
        Cookie password = new Cookie("value",value);
        System.out.println(key+"1===="+value);
        Cookie age=new Cookie("age","18");

        name.setMaxAge(60*60*24);
        password.setMaxAge(60*60*24);

        response.setContentType("utf-8");
        response.addCookie(name);
        response.addCookie(password);
        response.addCookie(age);
        System.out.println(key+"2===="+value);
    }
}
